import json


def parse_origin_log(input_file, output_file):
    with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
        for line in infile:
            try:
                log_entry = json.loads(line)
                content = log_entry.get('content', '')
                start_index = content.find('DetectChatLanguage: {')
                if start_index != -1:
                    start_index += len('DetectChatLanguage: ')
                    end_index = content.rfind('}')
                    if end_index != -1:
                        sensitive_words_filter_res = content[start_index:end_index + 1]
                        outfile.write(sensitive_words_filter_res + '\n')
            except json.JSONDecodeError:
                print(f"Error decoding JSON from line: {line}")


# 使用函数
parse_origin_log('./origin_log.json', './data.json')
